from flask import Blueprint, request

from apps.extention.business.project import CiProjectBusiness
from apps.extention.extentions import parse_json_form, validation
from library.api.render import json_detail_render

ciproject = Blueprint('ciproject', __name__)


@ciproject.route('/', methods=['POST'])
@validation('POST:ciproject')
def create_project():
    name, git_url, git_project_id, project_type, module_name, members, exclusions, dingding = parse_json_form(
        'ciproject')
    code, data, message = CiProjectBusiness.create_project(name, git_url, git_project_id, project_type, module_name,
                                                           members,
                                                           exclusions, dingding)
    return json_detail_render(code, data, message)


@ciproject.route('/', methods=['POST'])
def edit_project():
    pass


@ciproject.route('list')
def get_project_list():
    data = CiProjectBusiness.query_all_json()
    return json_detail_render(0, data)
